//
//  BKXUserAccount.swift
//  微博
//
//  Created by 田凯 on 16/4/19.
//  Copyright © 2016年 田凯. All rights reserved.
//

import UIKit

class BKXUserAccount: NSObject,NSCoding{
    // 用户授权的唯一票据
    var access_token: String?
    //access_token的生命周期
    var expires_in: Int = 0{
        didSet{
        expires_Date = NSDate().dateByAddingTimeInterval(Double(expires_in))
        
        }
        
    }
    //授权用户的UID
    var uid: String?
    var expires_Date: NSDate?
    //用户头像
    var profile_image_url: String?
    var name: String?
    
    
    //通过kvc 赋值
    init(dict: [String: AnyObject ]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
   override var description :String{
    let keys = ["access_token","expires_in","uid","expires_Date"]
    return dictionaryWithValuesForKeys(keys).description
    }
    
    //归档
    
    func encodeWithCoder(aCoder: NSCoder) {
        aCoder.encodeObject(access_token, forKey: "access_token")
        aCoder.encodeObject(expires_in, forKey: "expires_in")
        aCoder.encodeObject(uid, forKey: "uid")
        aCoder.encodeObject(expires_Date, forKey: "expires_Date")
        aCoder.encodeObject(profile_image_url, forKey: "profile_image_url")
        aCoder.encodeObject(name, forKey: "name")

        
    }
    required init?(coder aDecoder: NSCoder) {
        access_token = aDecoder.decodeObjectForKey("access_token")as? String
        uid = aDecoder.decodeObjectForKey("uid")as? String
        expires_Date = aDecoder.decodeObjectForKey("expires_Date")as? NSDate
        profile_image_url = aDecoder.decodeObjectForKey("profile_image_url")as? String
        name = aDecoder.decodeObjectForKey("name")as? String
    }
    
    
    

}
